package hl.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;

import hl.pageModel.AppInfo;
import hl.pageModel.DataGrid;
import hl.pageModel.Json;
import hl.service.AppInfoService;

@Namespace("/")
@Action(value = "appInfoAction")
public class AppInfoAction extends BaseAction implements ModelDriven<AppInfo> {

	AppInfo appInfo = new AppInfo();

	private AppInfoService appInfoService;

	@Override
	public AppInfo getModel() {
		return appInfo;
	}

	public AppInfoService getAppInfoService() {
		return appInfoService;
	}

	@Autowired
	public void setAppInfoService(AppInfoService appInfoService) {
		this.appInfoService = appInfoService;
	}

	public void add() {
		Json j = new Json();
		try {
			appInfoService.save(appInfo);
			j.setSuccess(true);
			j.setMsg("保存成功");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void getDatagrid() {
		DataGrid d = appInfoService.getDatagrid(appInfo);
		super.writeJson(d);
	}

	public void edit() {
		Json j = new Json();
		try {
			appInfoService.edit(appInfo);
			j.setSuccess(true);
			j.setMsg("修改成功！");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void remove() {
		Json j = new Json();
		try {
			appInfoService.remove(appInfo);
			j.setSuccess(true);
			j.setMsg("删除成功！");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}
	
	public void getComboBox() {
		super.writeJson(appInfoService.getComboBox(appInfo));
	}
}
